<?php 
namespace XFCore\traits\admin;
/*
*订单配置
*/
trait OrderTrait{
    public function orderstatus(){
        if($this->islogin_admin!=1)exitjson(-1,'请先登录');
        $trade_no = input("post")['trade_no'];
        if(empty($trade_no))exitjson(-1,'非法操作');
        $srow = $this->db->orderrow($trade_no , 'trade_no' , 'status');
        if(empty($srow))exitjson(-1,'数据不存在');
        $params = [
            'status' =>$srow['status'] == 1 ? 0 : 1,
        ];
        if($status == 1){
            $params['endtime'] = $this->date;
        }
        if($this->db->update('order',$params,['trade_no'=>$trade_no]))exitjson(200,'更新状态成功');
        exitjson(-1,'更新状态失败！');
        
    }
    public function orderdelete(){
        if($this->islogin_admin!=1)exitjson(-1,'请先登录');
        $trade_no = input("post")['trade_no'];
        if(empty($trade_no))exitjson(-1,'非法操作');
        
        $srow = $this->db->orderrow($trade_no);
        if(empty($srow))exitjson(-1,'数据不存在');
        if($this->db->delete("order",['id'=>$srow['id']])){
            createLog('删除订单成功',http_ip(),'admin');
            exitjson(200,'删除成功！');
        }
        exitjson(-1,'删除失败!');
    }
    public function orderbatchRemove(){
       if($this->islogin_admin!=1)exitjson(-1,"请先登录！");
       $id = explode(",", trim(input("post")['ids']));
       if(empty($id))exitjson(-1,'未选中数据！');
       $count = count($id);
       $succ = 0;
       createLog('批量删除订单成功',http_ip(),'admin');
       foreach ($id as $v) {
    		$this->db->delete('order',['trade_no'=>$v]);
    	}
    	exitjson(200,'删除成功');
    }
    public function orderallRemove(){
        if($this->islogin_admin!=1)exitjson(-1,"请先登录！");
        if(!$this->db->orderrow(2,'status'))exitjson(-1,'无未支付订单');
        if($this->db->delete('order',['status'=>2])){
            createLog('一键删除 未支付订单成功',http_ip() , 'admin');
            exitjson(200,'删除成功');
        }
        exitjson(-1,'删除失败！');
    }
}

?>